package com.kwq.designPattern.generate.prototype;

import lombok.Data;

import java.io.Serializable;

/**
 * @author kangwanqiang
 * @date 2021/2/4
 * @description 原型类，声明一个自己创建自己的接口clone()
 *              区分深拷贝与浅拷贝，浅拷贝在对对象进行拷贝时，只拷贝对象的引用，不会对对象进行复制
 */
@Data
public class ConcretePrototype implements Serializable, Cloneable {
    String name;
    Integer age;

    @Override
    public String toString() {
        return "ConcretePrototype{" + "name='" + name + '\'' + ", age=" + age
                + '}';
    }

    public ConcretePrototype(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 重写父类的保护类型的克隆函数
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
